import { getMachineStatus } from '../../api/index.js'

// pages/buyStatus/buyStatus.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabList: [
      {
        name: '申请中',
        status: 1
      },
      {
        name: '已购入',
        status: 2
      },
      {
        name: '驳回',
        status: 3
      }
    ],
    buyData: [
      {
        createTime: '2018-09-09',
        status: 1, // 1：申请中 2：申请成功 3: 申请失败,
        number: 200,
        reason: '未收到款项'
      }
    ]
  },

  onShow: function() {
    this.getMachineStatus()
  },

  getMachineStatus: function(status=1) {
    getMachineStatus({status})
    .then(res => {
      this.setData({
        buyData: res.data
      })
      console.log(res, '渲染购机状态');
    })
    .catch(e => {
      console.log(e, '购机状态')
    })
  },

  change: function(e) {
    const {detail:{status}} = e
    console.log(e, 'render change status')
    
    this.getMachineStatus(status)

  }
  
})